package com.example.tobebigfe.jsbridge

import android.content.Intent
import android.webkit.WebView
import org.json.JSONObject

class JSBridgeNavigation(val activity: WebActivity, webView: WebView) : BridgeModuleBase(webView) {

    override fun callFunc(func: String, callbackId: String, arg: JSONObject) {
        when (func) {
            "open" -> open(callbackId, arg)
            "close" -> close(callbackId, arg)
        }
    }

    private fun open(callbackId: String, arg: JSONObject) {
        val intent = Intent(activity, WebActivity::class.java)
        intent.putExtra("url", arg.getString("url"))
        activity.startActivity(intent)
    }

    private fun close(callbackId: String, arg: JSONObject) {
        activity.finish()
    }

}